import Taro, { Component } from '@tarojs/taro'
import { View, Image, RichText } from '@tarojs/components'
import { DItemTime } from '../../../components/index'
import '../itemdetail.scss'
import http from '@/api'
const awaitBg = require('../../assets/clock.png')
const successBg = require('../../assets/succeed01.png')
const failBg = require('../../assets/fail01.png')

export default class DHeader extends Component {

  constructor(props) {
    super(props)
    this.state = {
      bg: ""
    }
  }

  componentWillMount() {
    this.getStatusBg()
  }
  onTimeUp(t) {
    this.refuseSaleOrder(this.$router.params.id)
  }
  refuseSaleOrder(orderId) {
    alert(orderId)
    return
    // http.refuseSaleOrder({ orderId: orderId }).then((res) => {
    //   if (!res) {
    //     return
    //   }
    //   Taro.redirectTo({
    //     url: `/pages/itemdetail/saledetail?id=${orderId}&status=42`
    //   })
    // })
  }
  getStatusBg() {
    let { status = 1 } = this.props
    let _objBg = {
      1: awaitBg,
      2: successBg,
      3: failBg
    }
    this.setState({
      bg: _objBg[status]
    })
  }

  render() {
    const {
      bg
    } = this.state
    const {
      title,
      isdraw = false,
      account = 'CL12312312',
      text = '',
      itemtime = {
        isShowDay: false,
        sisShowHour: true,
        day: 0,
        hours: 0,
        minutes: 30,
        seconds: 0
      },
      tiptext = ''
    } = this.props
    return (
      <View className='b_itemdetail__header'>
        {!isdraw && <View className='b_itemdetail__header_status'>
          <Image className='b_itemdetail__header_image' src={bg}></Image>
          {
            title && <View className='b_itemdetail__header_title'>{title}</View>
          }
        </View>}
        <View className='b_itemdetail__header_desc'>
          <View className='b_itemdetail__header_desc__left'>
            <View className='b_itemdetail__header_number'>{isdraw ? '退款订单' : '订单编号'}：{account}</View>
            {
              text && <RichText className='b_itemdetail__header_text' nodes={text}></RichText>
            }
          </View>
          <View className='b_itemdetail__header_desc__right'>
            {isdraw && <View className="t-right rigTipBtn">退款成功</View>}
            {itemtime.day > 0 &&
              <View className='b_itemdetail__header_time'>
                <DItemTime onTimeUp={this.onTimeUp.bind(this)} {...itemtime} ></DItemTime>
              </View>
            }
            {itemtime.day > 0 && tiptext && <View className='b_itemdetail__header_tip'>{tiptext}</View>}
          </View>
        </View>
      </View>
    )
  }
}

DHeader.defaultProps = {
  status: 1
}
